<!DOCTYPE html>  
<html>  
<head>  
  
<script type="text/javascript" charset="utf-8" >  
  window.WebSocket = window.WebSocket || window.MozWebSocket;  
    
 if (!window.WebSocket){  
     alert("WebSocket not supported by this browser");  
 }
    
var websocket = new WebSocket("wss://127.0.0.1:12171");
 websocket.onmessage = function(evt){  
     var data = evt.data;  
     alert("received message: " + data);
 }

  websocket.onopen = function () {
     console.log("WebSocket 连接已经建立");
     websocket.send("hello,server")
  }
  
 function send() {  
 var name = document.getElementById('name').value;
    alert("websocket send message:"+name);  
    websocket.send(name);  
 }  
</script>  
</head>  
<body>  
<label for="name">What's your name:</label>
<input type="text" id="name" name="name" id='name'/>  
<button onclick="send()">Send</button>  
<div id="message" style="color:red"></div>  
</body>  
</html>  